// index.js
// 日记聚合页


import util from '../../../utils/util.js';
import { getObjectFromStorgeSync,KEYS} from '../../../utils/http.js';
var app = getApp();

Page({
  data: {
    infolist:[],
    type: 0,
    active:0,
    sticky:true,
    fixed:false,
    current: 1,
    verticalCurrent: 1
  },
  onChange(event) {
    this.setData({
      type: event.detail.index,
      current: event.detail.index+2,
      verticalCurrent: event.detail.index + 2,
    },()=>{
      this.getlist();
    });
  },
  onShow: function () {
    this.getlist();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:function(options) {
  
  },

  bindTap1: function () {
    var that = this;
    this.setData({
      type: 0,
    });
    that.getlist();
  },

  bindTap2: function () {
    var that = this;
    this.setData({
      type: 1,
    });
    that.getlist();

  },
  bindTap3: function () {
    var that = this;
    this.setData({
      type: 2,
    });
    that.getlist();

  },

  getlist(){
    var url = app.globalData.SERVER+'contact/getMyOrderRepairListByCarer2';
    var usetinfo = util.getData("userinfo");
    var usetinfo_id = usetinfo._id;
    const shop = getObjectFromStorgeSync(KEYS.SHOP)
    var status= this.data.type;
    util.request(url, 'POST', {
      state: status,
      carerid: usetinfo_id,
      shopid: shop._id
    }).then(res => {
      util.showToast('成功', 'error', 2500);
    }).catch(err => {
      if (err.data.code === 1 ) {
        console.log(err.data.ret);
        this.setData({
          infolist: err.data.ret,
        });
        var  num = 1;
      } else {
        self.setData({
          siteInfo: err.data.site_info
        });
      }
    });
  }
})
